Skip to contentSkip to conversation

Change in openvpn[master]: Support CIDR on options and extend netbits usage

Openvpn-devel New ralf_lici (Code Review) 2 participants 28 messages Sep 9, 2024 – Mar 16 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1725894771000.Iae04ad8715e40dfc76475c2c5b9a766c9604efc9@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to review the following change.

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Support CIDR on options and extend netbits usage

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-pull, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). Anyway push of ifconfig is done without CIDR in order to support older peers. Also netmask env vars have been preserved while also introducing the corresponding netbits vars.

Some of the internal logic has also been modified to use netbits instead of netmasks.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M src/openvpn/basic.h
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/helper.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/pool.c
M src/openvpn/push.c
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.c
M src/openvpn/tun.h

17 files changed, 521 insertions(+), 284 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/1

src/openvpn/basic.h +1 -0
index d1075b2..6658008 100644
@@ -33,5 +33,6 @@
 #define CLEAR(x) memset(&(x), 0, sizeof(x))
 
 #define IPV4_NETMASK_HOST 0xffffffffU
+#define IPV4_NETBITS_HOST 32U
 
 #endif
src/openvpn/clinat.c +28 -9
index 2d3b359..eaf5abb 100644
@@ -31,6 +31,7 @@
 #include "proto.h"
 #include "socket.h"
 #include "memdbg.h"
+#include "route.h"
 
 static bool
 add_entry(struct client_nat_option_list *dest,
@@ -60,11 +61,11 @@
         for (i = 0; i < list->n; ++i)
         {
             const struct client_nat_entry *e = &list->entries[i];
-            msg(msglevel, "  CNAT[%d] t=%d %s/%s/%s",
+            msg(msglevel, "  CNAT[%d] t=%d %s/%d %s",
                 i,
                 e->type,
                 print_in_addr_t(e->network, IA_NET_ORDER, &gc),
-                print_in_addr_t(e->netmask, IA_NET_ORDER, &gc),
+                e->netbits,
                 print_in_addr_t(e->foreign_network, IA_NET_ORDER, &gc));
         }
     }
@@ -111,6 +112,7 @@
                               int msglevel)
 {
     struct client_nat_entry e;
+    unsigned int netbits = 0;
     bool ok;
 
     if (!strcmp(type, "snat"))
@@ -127,19 +129,35 @@
         return;
     }
 
-    e.network = getaddr(0, network, 0, &ok, NULL);
+    e.network = getaddr(0, network, &netbits, 0, &ok, NULL);
     if (!ok)
     {
         msg(msglevel, "client-nat: bad network: %s", network);
         return;
     }
-    e.netmask = getaddr(0, netmask, 0, &ok, NULL);
-    if (!ok)
+    if (netmask)
     {
-        msg(msglevel, "client-nat: bad netmask: %s", netmask);
+        const in_addr_t mask = getaddr(0, netmask, NULL, 0, &ok, NULL);
+        const int bits = netmask_to_netbits2(mask);
+
+        if (!ok || bits <= 0)
+        {
+            msg(msglevel, "client-nat: bad netmask: %s", netmask);
+            return;
+        }
+        msg(M_WARN, "client-nat network parameter can also be specified as a CIDR address instead of using the separate netmask parameter");
+        e.netbits = bits;
+    }
+    else if (netbits > 0)
+    {
+        e.netbits = netbits;
+    }
+    else
+    {
+        msg(msglevel, "client-nat: netmask or bits must be specified");
         return;
     }
-    e.foreign_network = getaddr(0, foreign_network, 0, &ok, NULL);
+    e.foreign_network = getaddr(0, foreign_network, NULL, 0, &ok, NULL);
     if (!ok)
     {
         msg(msglevel, "client-nat: bad foreign network: %s", foreign_network);
@@ -210,6 +228,7 @@
     for (i = 0; i < list->n; ++i)
     {
         const struct client_nat_entry *e = &list->entries[i]; /* current NAT rule */
+        const in_addr_t netmask = netbits_to_netmask((int)e->netbits);
         if (e->type ^ direction)
         {
             addr = *(addr_ptr = &h->ip.daddr);
@@ -231,13 +250,13 @@
             to = &e->foreign_network;
         }
 
-        if (((addr & e->netmask) == *from) && !(amask & alog))
+        if (((addr & netmask) == *from) && !(amask & alog))
         {
             /* pre-adjust IP checksum */
             ADD_CHECKSUM_32(accumulate, addr);
 
             /* do NAT transform */
-            addr = (addr & ~e->netmask) | *to;
+            addr = (addr & ~netmask) | *to;
 
             /* post-adjust IP checksum */
             SUB_CHECKSUM_32(accumulate, addr);
src/openvpn/clinat.h +1 -1
index 94141f5..bebd012 100644
@@ -36,7 +36,7 @@
 #define CN_DNAT 1
     int type;
     in_addr_t network;
-    in_addr_t netmask;
+    unsigned int netbits;
     in_addr_t foreign_network;
 };
 
src/openvpn/helper.c +33 -46

201 lines not on this page · raw message

src/openvpn/init.c +21 -7
index dd56961..7f72f8d 100644
@@ -115,6 +115,7 @@
             const char *dev_type,
             int tun_mtu,
             const char *ifconfig_local,
+            const int ifconfig_netbits,
             const char *ifconfig_remote,
             const char *context,
             const char *signal_text,
@@ -144,7 +145,14 @@
     }
     if (!ifconfig_remote)
     {
-        ifconfig_remote = "";
+        if (ifconfig_netbits > 0)
+        {
+            ifconfig_remote = print_in_addr_t(netbits_to_netmask(ifconfig_netbits), 0, &gc);
+        }
+        else
+        {
+            ifconfig_remote = "";
+        }
     }
     if (!context)
     {
@@ -1948,7 +1956,8 @@
                     dev_type_string(c->options.dev, c->options.dev_type),
                     c->c2.frame.tun_mtu,
                     print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
-                    print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                    c->c1.tuntap->netbits,
+                    print_in_addr_t(c->c1.tuntap->remote, IA_EMPTY_IF_UNDEF, &gc),
                     "init",
                     NULL,
                     "up",
@@ -1988,7 +1997,8 @@
                         dev_type_string(c->options.dev, c->options.dev_type),
                         c->c2.frame.tun_mtu,
                         print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
-                        print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                        c->c1.tuntap->netbits,
+                        print_in_addr_t(c->c1.tuntap->remote, IA_EMPTY_IF_UNDEF, &gc),
                         "restart",
                         NULL,
                         "up",
@@ -2045,7 +2055,8 @@
     struct gc_arena gc = gc_new();
     const char *tuntap_actual = string_alloc(c->c1.tuntap->actual_name, &gc);
     const in_addr_t local = c->c1.tuntap->local;
-    const in_addr_t remote_netmask = c->c1.tuntap->remote_netmask;
+    const int netbits = c->c1.tuntap->netbits;
+    const in_addr_t remote = c->c1.tuntap->remote;
     unsigned long adapter_index = 0;
 #ifdef _WIN32
     adapter_index = c->c1.tuntap->adapter_index;
@@ -2077,7 +2088,8 @@
                         NULL,
                         c->c2.frame.tun_mtu,
                         print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
-                        print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                        netbits,
+                        print_in_addr_t(remote, IA_EMPTY_IF_UNDEF, &gc),
                         "init",
                         signal_description(c->sig->signal_received,
                                            c->sig->signal_text),
@@ -2107,7 +2119,8 @@
                     NULL,
                     c->c2.frame.tun_mtu,
                     print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
-                    print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                    netbits,
+                    print_in_addr_t(remote, IA_EMPTY_IF_UNDEF, &gc),
                     "init",
                     signal_description(c->sig->signal_received,
                                        c->sig->signal_text),
@@ -2137,7 +2150,8 @@
                         NULL,
                         c->c2.frame.tun_mtu,
                         print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
-                        print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                        netbits,
+                        print_in_addr_t(remote, IA_EMPTY_IF_UNDEF, &gc),
                         "restart",
                         signal_description(c->sig->signal_received,
                                            c->sig->signal_text),
src/openvpn/manage.c +2 -1
index 05b5a1a..a88ee5f 100644
@@ -554,7 +554,7 @@
         {
             /* IP:port specified */
             bool status;
-            const in_addr_t addr = getaddr(GETADDR_HOST_ORDER|GETADDR_MSG_VIRT_OUT, p1, 0, &status, NULL);
+            const in_addr_t addr = getaddr(GETADDR_HOST_ORDER|GETADDR_MSG_VIRT_OUT, p1, NULL, 0, &status, NULL);
             if (status)
             {
                 const int port = atoi(p2);
@@ -2803,6 +2803,7 @@
         "untrusted_ip=",
         "ifconfig_local=",
         "ifconfig_netmask=",
+        "ifconfig_netbits=",
         "daemon_start_time=",
         "daemon_pid=",
         "dev=",
src/openvpn/multi.c +7 -7
index 0509911..aba1a0f 100644
@@ -1433,7 +1433,8 @@
     const struct options *o = &c->options;
     if (o->push_ifconfig_constraint_defined && c->c2.push_ifconfig_defined)
     {
-        return (o->push_ifconfig_constraint_netmask & c->c2.push_ifconfig_local) == o->push_ifconfig_constraint_network;
+        const unsigned int var = 32 - o->push_ifconfig_constraint_netbits;
+        return (c->c2.push_ifconfig_local >> var) == (o->push_ifconfig_constraint_network >> var);
     }
     else
     {
@@ -1512,10 +1513,10 @@
                 mi->context.c2.push_ifconfig_local = remote;
                 if (tunnel_type == DEV_TYPE_TAP || (tunnel_type == DEV_TYPE_TUN && tunnel_topology == TOP_SUBNET))
                 {
-                    mi->context.c2.push_ifconfig_remote_netmask = mi->context.options.ifconfig_pool_netmask;
+                    mi->context.c2.push_ifconfig_remote_netmask = netbits_to_netmask((int)mi->context.options.ifconfig_pool_netbits);
                     if (!mi->context.c2.push_ifconfig_remote_netmask)
                     {
-                        mi->context.c2.push_ifconfig_remote_netmask = mi->context.c1.tuntap->remote_netmask;
+                        mi->context.c2.push_ifconfig_remote_netmask = netbits_to_netmask((int)mi->context.c1.tuntap->netbits);
                     }
                 }
                 else if (tunnel_type == DEV_TYPE_TUN)
@@ -2425,15 +2426,14 @@
     {
         const char *ifconfig_constraint_network =
             print_in_addr_t(mi->context.options.push_ifconfig_constraint_network, 0, &gc);
-        const char *ifconfig_constraint_netmask =
-            print_in_addr_t(mi->context.options.push_ifconfig_constraint_netmask, 0, &gc);
 
         /* JYFIXME -- this should cause the connection to fail */
         msg(D_MULTI_ERRORS, "MULTI ERROR: primary virtual IP for %s (%s) "
-            "violates tunnel network/netmask constraint (%s/%s)",
+            "violates tunnel network/subnet constraint (%s/%d)",
             multi_instance_string(mi, false, &gc),
             print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc),
-            ifconfig_constraint_network, ifconfig_constraint_netmask);
+            ifconfig_constraint_network,
+            mi->context.options.push_ifconfig_constraint_netbits);
     }
 
     /*
src/openvpn/options.c +197 -66

442 lines not on this page · raw message

src/openvpn/options.h +4 -4
index f608cb8..88de24c 100644
@@ -450,7 +450,7 @@
     const char *tmp_dir;
     bool server_defined;
     in_addr_t server_network;
-    in_addr_t server_netmask;
+    unsigned int server_netbits;
     bool server_ipv6_defined;                           /* IPv6 */
     struct in6_addr server_network_ipv6;                /* IPv6 */
     unsigned int server_netbits_ipv6;                   /* IPv6 */
@@ -464,7 +464,7 @@
 
     bool server_bridge_defined;
     in_addr_t server_bridge_ip;
-    in_addr_t server_bridge_netmask;
+    unsigned int server_bridge_netbits;
     in_addr_t server_bridge_pool_start;
     in_addr_t server_bridge_pool_end;
 
@@ -472,7 +472,7 @@
     bool ifconfig_pool_defined;
     in_addr_t ifconfig_pool_start;
     in_addr_t ifconfig_pool_end;
-    in_addr_t ifconfig_pool_netmask;
+    unsigned int ifconfig_pool_netbits;
     const char *ifconfig_pool_persist_filename;
     int ifconfig_pool_persist_refresh_freq;
 
@@ -499,7 +499,7 @@
     in_addr_t push_ifconfig_local_alias;
     bool push_ifconfig_constraint_defined;
     in_addr_t push_ifconfig_constraint_network;
-    in_addr_t push_ifconfig_constraint_netmask;
+    unsigned int push_ifconfig_constraint_netbits;
     bool push_ifconfig_ipv4_blocked;                    /* IPv4 */
     bool push_ifconfig_ipv6_defined;                    /* IPv6 */
     struct in6_addr push_ifconfig_ipv6_local;           /* IPv6 */
src/openvpn/pool.c +2 -2
index e3c3708..84227b6 100644
@@ -652,8 +652,8 @@
             if (strlen(ip_buf) > 0)
             {
                 bool v4_ok = true;
-                in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, 0, &v4_ok,
-                                         NULL);
+                in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, NULL, 0,
+                                         &v4_ok, NULL);
 
                 if (!v4_ok)
                 {
src/openvpn/push.c +15 -4
index 6c06374..b8ab470 100644
@@ -1136,9 +1136,20 @@
                 if (p[0] && !strcmp(p[0], "route") && !p[3] && o->iroutes)
                 {
                     /* get route parameters */
-                    bool status1, status2;
-                    const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], 0, &status1, NULL);
-                    const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255.255", 0, &status2, NULL);
+                    bool status1, status2 = true;
+                    int netbits = -1;
+
+                    /* get netbits from CIDR or convert netmask to netbits */
+                    const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], (unsigned int *)&netbits, 0, &status1, NULL);
+                    if (p[2])
+                    {
+                        const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, p[2], NULL, 0, &status2, NULL);
+                        netbits = netmask_to_netbits2(netmask);
+                    }
+                    if (netbits <= 0)
+                    {
+                        netbits = 32;
+                    }
 
                     /* did route parameters parse correctly? */
                     if (status1 && status2)
@@ -1148,7 +1159,7 @@
                         /* does route match an iroute? */
                         for (ir = o->iroutes; ir != NULL; ir = ir->next)
                         {
-                            if (network == ir->network && netmask == netbits_to_netmask(ir->netbits >= 0 ? ir->netbits : 32))
+                            if (network == ir->network && netbits == (ir->netbits >= 0 ? ir->netbits : 32))
                             {
                                 enable = false;
                                 break;
src/openvpn/route.c +78 -48

408 lines not on this page · raw message

src/openvpn/route.h +1 -1
index 421e7d2..a117584 100644
@@ -117,7 +117,7 @@
     unsigned int flags;
     const struct route_option *option;
     in_addr_t network;
-    in_addr_t netmask;
+    unsigned int netbits;
     in_addr_t gateway;
     int metric;
 };
src/openvpn/socket.c +2 -1
index 17c5e76..767036f 100644
@@ -179,6 +179,7 @@
 in_addr_t
 getaddr(unsigned int flags,
         const char *hostname,
+        unsigned int *netbits,
         int resolve_retry_seconds,
         bool *succeeded,
         struct signal_info *sig_info)
@@ -186,7 +187,7 @@
     in_addr_t addr;
     int status;
 
-    status = get_addr_generic(AF_INET, flags, hostname, &addr, NULL,
+    status = get_addr_generic(AF_INET, flags, hostname, &addr, netbits,
                               resolve_retry_seconds, sig_info,
                               M_WARN);
     if (status==0)
src/openvpn/socket.h +1 -0
index 47083ad..f6165b2 100644
@@ -524,6 +524,7 @@
  */
 in_addr_t getaddr(unsigned int flags,
                   const char *hostname,
+                  unsigned int *netbits,
                   int resolve_retry_seconds,
                   bool *succeeded,
                   struct signal_info *sig_info);
src/openvpn/tun.c +126 -86

575 lines not on this page · raw message

src/openvpn/tun.h +2 -1
index 33b9552..68aa3b8 100644
@@ -188,7 +188,8 @@
 
     /* ifconfig parameters */
     in_addr_t local;
-    in_addr_t remote_netmask;
+    in_addr_t remote;
+    int netbits;
 
     struct in6_addr local_ipv6;
     struct in6_addr remote_ipv6;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#2).

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Support CIDR on options and extend netbits usage

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-pull, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). Anyway push of ifconfig is done without CIDR in order to support older peers. Also netmask env vars have been preserved while also introducing the corresponding netbits vars.

Some of the internal logic has also been modified to use netbits instead of netmasks.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M src/openvpn/basic.h
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/helper.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/pool.c
M src/openvpn/push.c
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.c
M src/openvpn/tun.h

17 files changed, 520 insertions(+), 284 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/2

src/openvpn/basic.h +1 -0
index d1075b2..6658008 100644
@@ -33,5 +33,6 @@
 #define CLEAR(x) memset(&(x), 0, sizeof(x))
 
 #define IPV4_NETMASK_HOST 0xffffffffU
+#define IPV4_NETBITS_HOST 32U
 
 #endif
src/openvpn/clinat.c +27 -9
index 2d3b359..f565989 100644
@@ -31,6 +31,7 @@
 #include "proto.h"
 #include "socket.h"
 #include "memdbg.h"
+#include "route.h"
 
 static bool
 add_entry(struct client_nat_option_list *dest,
@@ -60,11 +61,11 @@
         for (i = 0; i < list->n; ++i)
         {
             const struct client_nat_entry *e = &list->entries[i];
-            msg(msglevel, "  CNAT[%d] t=%d %s/%s/%s",
+            msg(msglevel, "  CNAT[%d] t=%d %s/%d %s",
                 i,
                 e->type,
                 print_in_addr_t(e->network, IA_NET_ORDER, &gc),
-                print_in_addr_t(e->netmask, IA_NET_ORDER, &gc),
+                e->netbits,
                 print_in_addr_t(e->foreign_network, IA_NET_ORDER, &gc));
         }
     }
@@ -111,6 +112,7 @@
                               int msglevel)
 {
     struct client_nat_entry e;
+    unsigned int netbits = 0;
     bool ok;
 
     if (!strcmp(type, "snat"))
@@ -127,19 +129,34 @@
         return;
     }
 
-    e.network = getaddr(0, network, 0, &ok, NULL);
+    e.network = getaddr(0, network, &netbits, 0, &ok, NULL);
     if (!ok)
     {
         msg(msglevel, "client-nat: bad network: %s", network);
         return;
     }
-    e.netmask = getaddr(0, netmask, 0, &ok, NULL);
-    if (!ok)
+    if (netmask)
     {
-        msg(msglevel, "client-nat: bad netmask: %s", netmask);
+        const in_addr_t mask = getaddr(0, netmask, NULL, 0, &ok, NULL);
+        const int bits = netmask_to_netbits2(mask);
+
+        if (!ok || bits <= 0)
+        {
+            msg(msglevel, "client-nat: bad netmask: %s", netmask);
+            return;
+        }
+        e.netbits = bits;
+    }
+    else if (netbits > 0)
+    {
+        e.netbits = netbits;
+    }
+    else
+    {
+        msg(msglevel, "client-nat: netmask or bits must be specified");
         return;
     }
-    e.foreign_network = getaddr(0, foreign_network, 0, &ok, NULL);
+    e.foreign_network = getaddr(0, foreign_network, NULL, 0, &ok, NULL);
     if (!ok)
     {
         msg(msglevel, "client-nat: bad foreign network: %s", foreign_network);
@@ -210,6 +227,7 @@
     for (i = 0; i < list->n; ++i)
     {
         const struct client_nat_entry *e = &list->entries[i]; /* current NAT rule */
+        const in_addr_t netmask = netbits_to_netmask((int)e->netbits);
         if (e->type ^ direction)
         {
             addr = *(addr_ptr = &h->ip.daddr);
@@ -231,13 +249,13 @@
             to = &e->foreign_network;
         }
 
-        if (((addr & e->netmask) == *from) && !(amask & alog))
+        if (((addr & netmask) == *from) && !(amask & alog))
         {
             /* pre-adjust IP checksum */
             ADD_CHECKSUM_32(accumulate, addr);
 
             /* do NAT transform */
-            addr = (addr & ~e->netmask) | *to;
+            addr = (addr & ~netmask) | *to;
 
             /* post-adjust IP checksum */
             SUB_CHECKSUM_32(accumulate, addr);
src/openvpn/clinat.h +1 -1
index 94141f5..bebd012 100644
@@ -36,7 +36,7 @@
 #define CN_DNAT 1
     int type;
     in_addr_t network;
-    in_addr_t netmask;
+    unsigned int netbits;
     in_addr_t foreign_network;
 };
 
src/openvpn/helper.c +33 -46

201 lines not on this page · raw message

src/openvpn/init.c +21 -7
index dd56961..7f72f8d 100644
@@ -115,6 +115,7 @@
             const char *dev_type,
             int tun_mtu,
             const char *ifconfig_local,
+            const int ifconfig_netbits,
             const char *ifconfig_remote,
             const char *context,
             const char *signal_text,
@@ -144,7 +145,14 @@
     }
     if (!ifconfig_remote)
     {
-        ifconfig_remote = "";
+        if (ifconfig_netbits > 0)
+        {
+            ifconfig_remote = print_in_addr_t(netbits_to_netmask(ifconfig_netbits), 0, &gc);
+        }
+        else
+        {
+            ifconfig_remote = "";
+        }
     }
     if (!context)
     {
@@ -1948,7 +1956,8 @@
                     dev_type_string(c->options.dev, c->options.dev_type),
                     c->c2.frame.tun_mtu,
                     print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
-                    print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                    c->c1.tuntap->netbits,
+                    print_in_addr_t(c->c1.tuntap->remote, IA_EMPTY_IF_UNDEF, &gc),
                     "init",
                     NULL,
                     "up",
@@ -1988,7 +1997,8 @@
                         dev_type_string(c->options.dev, c->options.dev_type),
                         c->c2.frame.tun_mtu,
                         print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
-                        print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                        c->c1.tuntap->netbits,
+                        print_in_addr_t(c->c1.tuntap->remote, IA_EMPTY_IF_UNDEF, &gc),
                         "restart",
                         NULL,
                         "up",
@@ -2045,7 +2055,8 @@
     struct gc_arena gc = gc_new();
     const char *tuntap_actual = string_alloc(c->c1.tuntap->actual_name, &gc);
     const in_addr_t local = c->c1.tuntap->local;
-    const in_addr_t remote_netmask = c->c1.tuntap->remote_netmask;
+    const int netbits = c->c1.tuntap->netbits;
+    const in_addr_t remote = c->c1.tuntap->remote;
     unsigned long adapter_index = 0;
 #ifdef _WIN32
     adapter_index = c->c1.tuntap->adapter_index;
@@ -2077,7 +2088,8 @@
                         NULL,
                         c->c2.frame.tun_mtu,
                         print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
-                        print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                        netbits,
+                        print_in_addr_t(remote, IA_EMPTY_IF_UNDEF, &gc),
                         "init",
                         signal_description(c->sig->signal_received,
                                            c->sig->signal_text),
@@ -2107,7 +2119,8 @@
                     NULL,
                     c->c2.frame.tun_mtu,
                     print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
-                    print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                    netbits,
+                    print_in_addr_t(remote, IA_EMPTY_IF_UNDEF, &gc),
                     "init",
                     signal_description(c->sig->signal_received,
                                        c->sig->signal_text),
@@ -2137,7 +2150,8 @@
                         NULL,
                         c->c2.frame.tun_mtu,
                         print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
-                        print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
+                        netbits,
+                        print_in_addr_t(remote, IA_EMPTY_IF_UNDEF, &gc),
                         "restart",
                         signal_description(c->sig->signal_received,
                                            c->sig->signal_text),
src/openvpn/manage.c +2 -1
index 05b5a1a..a88ee5f 100644
@@ -554,7 +554,7 @@
         {
             /* IP:port specified */
             bool status;
-            const in_addr_t addr = getaddr(GETADDR_HOST_ORDER|GETADDR_MSG_VIRT_OUT, p1, 0, &status, NULL);
+            const in_addr_t addr = getaddr(GETADDR_HOST_ORDER|GETADDR_MSG_VIRT_OUT, p1, NULL, 0, &status, NULL);
             if (status)
             {
                 const int port = atoi(p2);
@@ -2803,6 +2803,7 @@
         "untrusted_ip=",
         "ifconfig_local=",
         "ifconfig_netmask=",
+        "ifconfig_netbits=",
         "daemon_start_time=",
         "daemon_pid=",
         "dev=",
src/openvpn/multi.c +7 -7
index 0509911..aba1a0f 100644
@@ -1433,7 +1433,8 @@
     const struct options *o = &c->options;
     if (o->push_ifconfig_constraint_defined && c->c2.push_ifconfig_defined)
     {
-        return (o->push_ifconfig_constraint_netmask & c->c2.push_ifconfig_local) == o->push_ifconfig_constraint_network;
+        const unsigned int var = 32 - o->push_ifconfig_constraint_netbits;
+        return (c->c2.push_ifconfig_local >> var) == (o->push_ifconfig_constraint_network >> var);
     }
     else
     {
@@ -1512,10 +1513,10 @@
                 mi->context.c2.push_ifconfig_local = remote;
                 if (tunnel_type == DEV_TYPE_TAP || (tunnel_type == DEV_TYPE_TUN && tunnel_topology == TOP_SUBNET))
                 {
-                    mi->context.c2.push_ifconfig_remote_netmask = mi->context.options.ifconfig_pool_netmask;
+                    mi->context.c2.push_ifconfig_remote_netmask = netbits_to_netmask((int)mi->context.options.ifconfig_pool_netbits);
                     if (!mi->context.c2.push_ifconfig_remote_netmask)
                     {
-                        mi->context.c2.push_ifconfig_remote_netmask = mi->context.c1.tuntap->remote_netmask;
+                        mi->context.c2.push_ifconfig_remote_netmask = netbits_to_netmask((int)mi->context.c1.tuntap->netbits);
                     }
                 }
                 else if (tunnel_type == DEV_TYPE_TUN)
@@ -2425,15 +2426,14 @@
     {
         const char *ifconfig_constraint_network =
             print_in_addr_t(mi->context.options.push_ifconfig_constraint_network, 0, &gc);
-        const char *ifconfig_constraint_netmask =
-            print_in_addr_t(mi->context.options.push_ifconfig_constraint_netmask, 0, &gc);
 
         /* JYFIXME -- this should cause the connection to fail */
         msg(D_MULTI_ERRORS, "MULTI ERROR: primary virtual IP for %s (%s) "
-            "violates tunnel network/netmask constraint (%s/%s)",
+            "violates tunnel network/subnet constraint (%s/%d)",
             multi_instance_string(mi, false, &gc),
             print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc),
-            ifconfig_constraint_network, ifconfig_constraint_netmask);
+            ifconfig_constraint_network,
+            mi->context.options.push_ifconfig_constraint_netbits);
     }
 
     /*
src/openvpn/options.c +192 -66

437 lines not on this page · raw message

src/openvpn/options.h +4 -4
index f608cb8..88de24c 100644
@@ -450,7 +450,7 @@
     const char *tmp_dir;
     bool server_defined;
     in_addr_t server_network;
-    in_addr_t server_netmask;
+    unsigned int server_netbits;
     bool server_ipv6_defined;                           /* IPv6 */
     struct in6_addr server_network_ipv6;                /* IPv6 */
     unsigned int server_netbits_ipv6;                   /* IPv6 */
@@ -464,7 +464,7 @@
 
     bool server_bridge_defined;
     in_addr_t server_bridge_ip;
-    in_addr_t server_bridge_netmask;
+    unsigned int server_bridge_netbits;
     in_addr_t server_bridge_pool_start;
     in_addr_t server_bridge_pool_end;
 
@@ -472,7 +472,7 @@
     bool ifconfig_pool_defined;
     in_addr_t ifconfig_pool_start;
     in_addr_t ifconfig_pool_end;
-    in_addr_t ifconfig_pool_netmask;
+    unsigned int ifconfig_pool_netbits;
     const char *ifconfig_pool_persist_filename;
     int ifconfig_pool_persist_refresh_freq;
 
@@ -499,7 +499,7 @@
     in_addr_t push_ifconfig_local_alias;
     bool push_ifconfig_constraint_defined;
     in_addr_t push_ifconfig_constraint_network;
-    in_addr_t push_ifconfig_constraint_netmask;
+    unsigned int push_ifconfig_constraint_netbits;
     bool push_ifconfig_ipv4_blocked;                    /* IPv4 */
     bool push_ifconfig_ipv6_defined;                    /* IPv6 */
     struct in6_addr push_ifconfig_ipv6_local;           /* IPv6 */
src/openvpn/pool.c +2 -2
index e3c3708..84227b6 100644
@@ -652,8 +652,8 @@
             if (strlen(ip_buf) > 0)
             {
                 bool v4_ok = true;
-                in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, 0, &v4_ok,
-                                         NULL);
+                in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, NULL, 0,
+                                         &v4_ok, NULL);
 
                 if (!v4_ok)
                 {
src/openvpn/push.c +15 -4
index 6c06374..b8ab470 100644
@@ -1136,9 +1136,20 @@
                 if (p[0] && !strcmp(p[0], "route") && !p[3] && o->iroutes)
                 {
                     /* get route parameters */
-                    bool status1, status2;
-                    const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], 0, &status1, NULL);
-                    const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255.255", 0, &status2, NULL);
+                    bool status1, status2 = true;
+                    int netbits = -1;
+
+                    /* get netbits from CIDR or convert netmask to netbits */
+                    const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], (unsigned int *)&netbits, 0, &status1, NULL);
+                    if (p[2])
+                    {
+                        const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, p[2], NULL, 0, &status2, NULL);
+                        netbits = netmask_to_netbits2(netmask);
+                    }
+                    if (netbits <= 0)
+                    {
+                        netbits = 32;
+                    }
 
                     /* did route parameters parse correctly? */
                     if (status1 && status2)
@@ -1148,7 +1159,7 @@
                         /* does route match an iroute? */
                         for (ir = o->iroutes; ir != NULL; ir = ir->next)
                         {
-                            if (network == ir->network && netmask == netbits_to_netmask(ir->netbits >= 0 ? ir->netbits : 32))
+                            if (network == ir->network && netbits == (ir->netbits >= 0 ? ir->netbits : 32))
                             {
                                 enable = false;
                                 break;
src/openvpn/route.c +77 -48

407 lines not on this page · raw message

src/openvpn/route.h +1 -1
index 421e7d2..a117584 100644
@@ -117,7 +117,7 @@
     unsigned int flags;
     const struct route_option *option;
     in_addr_t network;
-    in_addr_t netmask;
+    unsigned int netbits;
     in_addr_t gateway;
     int metric;
 };
src/openvpn/socket.c +2 -1
index 17c5e76..767036f 100644
@@ -179,6 +179,7 @@
 in_addr_t
 getaddr(unsigned int flags,
         const char *hostname,
+        unsigned int *netbits,
         int resolve_retry_seconds,
         bool *succeeded,
         struct signal_info *sig_info)
@@ -186,7 +187,7 @@
     in_addr_t addr;
     int status;
 
-    status = get_addr_generic(AF_INET, flags, hostname, &addr, NULL,
+    status = get_addr_generic(AF_INET, flags, hostname, &addr, netbits,
                               resolve_retry_seconds, sig_info,
                               M_WARN);
     if (status==0)
src/openvpn/socket.h +1 -0
index 47083ad..f6165b2 100644
@@ -524,6 +524,7 @@
  */
 in_addr_t getaddr(unsigned int flags,
                   const char *hostname,
+                  unsigned int *netbits,
                   int resolve_retry_seconds,
                   bool *succeeded,
                   struct signal_info *sig_info);
src/openvpn/tun.c +132 -86

582 lines not on this page · raw message

src/openvpn/tun.h +2 -1
index 33b9552..68aa3b8 100644
@@ -188,7 +188,8 @@
 
     /* ifconfig parameters */
     in_addr_t local;
-    in_addr_t remote_netmask;
+    in_addr_t remote;
+    int netbits;
 
     struct in6_addr local_ipv6;
     struct in6_addr remote_ipv6;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 2: Code-Review-2

(4 comments)

Patchset:

PS2:
Only started going through the code, so only a few comments. Without a documentation update I find it difficult to judge the changes. Please provide documentation update.

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/2909683e_d410ca3f :
PS2, Line 1516: msg(D_SHOW_PARMS, " server_network = %s/%d", print_in_addr_t(o->server_network, 0, &gc), o->server_netbits);
%u

http://gerrit.openvpn.net/c/openvpn/+/739/comment/5e27a458_e0728f32 :
PS2, Line 1519: msg(D_SHOW_PARMS, " server_bridge_ip = %s/%d", print_in_addr_t(o->server_bridge_ip, 0, &gc), o->server_bridge_netbits);
%u

http://gerrit.openvpn.net/c/openvpn/+/739/comment/f1263d0c_6227c36a :
PS2, Line 1535: msg(D_SHOW_PARMS, " ifconfig_pool_start = %s/%d", print_in_addr_t(o->ifconfig_pool_start, 0, &gc), o->ifconfig_pool_netbits);
%u

giving netbits with _start doesn't seem to make sense.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 13:07:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 2:

(4 comments)

Patchset:

PS2:

Quoted 1 line

Only started going through the code, so only a few comments. […]

Will do

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/2609ef1b_3e2658b8 :
PS2, Line 1516: msg(D_SHOW_PARMS, " server_network = %s/%d", print_in_addr_t(o->server_network, 0, &gc), o->server_netbits);

Quoted 1 line

%u

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/511cdb40_3a9d08f3 :
PS2, Line 1519: msg(D_SHOW_PARMS, " server_bridge_ip = %s/%d", print_in_addr_t(o->server_bridge_ip, 0, &gc), o->server_bridge_netbits);

Quoted 1 line

%u

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/af179191_a1b280d9 :
PS2, Line 1535: msg(D_SHOW_PARMS, " ifconfig_pool_start = %s/%d", print_in_addr_t(o->ifconfig_pool_start, 0, &gc), o->ifconfig_pool_netbits);

Quoted 1 line

%u […]

So you are suggesting avoiding netbits in this case?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 13:26:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 2:

(1 comment)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/200757a5_2e7e0aa5 :
PS2, Line 1535: msg(D_SHOW_PARMS, " ifconfig_pool_start = %s/%d", print_in_addr_t(o->ifconfig_pool_start, 0, &gc), o->ifconfig_pool_netbits);

Quoted 1 line

So you are suggesting avoiding netbits in this case?

I'm saying that we need to come up with a clearer display for the information. But I do not have a proposal right now. Maybe once I have looked deeper into the topic of why we actually have a start and an end and a netmask.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 13:55:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>
Gerrit-MessageType: comment

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 2:

(1 comment)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/550aedbd_8f511ee3 :
PS2, Line 1535: msg(D_SHOW_PARMS, " ifconfig_pool_start = %s/%d", print_in_addr_t(o->ifconfig_pool_start, 0, &gc), o->ifconfig_pool_netbits);

Quoted 1 line

I'm saying that we need to come up with a clearer display for the information. […]

ok

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 13:57:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>
Gerrit-MessageType: comment

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 3:

(1 comment)

Patchset:

PS3:
I extended to the doc pages on the options affected by this change. I restored --ifconfig-pool to the original format (no CIDR).

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 12 Sep 2024 14:06:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 3: Code-Review-2

(16 comments)

Patchset:

PS3:
Didn't get through the whole code, but here a collection of my thoughts so far...

File doc/man-sections/server-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/04a8784d_9d0d84d0 :
PS3, Line 344: :code:255.255.255.255.
for completeness mentions /32 as well.

File doc/man-sections/vpn-network-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/7f755556_b75a572a :
PS3, Line 220: ifconfig local rn
Need to specify the two possibilities (IP address or netmask) separately. Also "rn" is a horrible name. What it is supposed to mean?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/9e59c2d1_8882b7e2 :
PS3, Line 266: 2 255
Add /bits example here?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/f33e5bdd_a494b3ca :
PS3, Line 389: route network|ipv4addr [netmask] [gateway] [metric]
Does the network|ipv4addr here really add any value? Should we go just for ipv4addr here like with --route-ipv6 ?

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/f3ac4520_d5a41ab2 :
PS2, Line 1535: msg(D_SHOW_PARMS, " ifconfig_pool_start = %s/%d", print_in_addr_t(o->ifconfig_pool_start, 0, &gc), o->ifconfig_pool_netbits);

Quoted 1 line

ok

Done

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/483600ca_2e578b22 :
PS3, Line 6103: if (!p[2]) /* p[1] must be in CIDR format */
Should probably do a ip_or_dns_addr_safe(p[1]) here? Might need to enhance that function to allow netbits, though.

http://gerrit.openvpn.net/c/openvpn/+/739/comment/37d80b88_d3071bd7 :
PS3, Line 7029: VERIFY_PERMISSION
VERIFY_PERMISSION should go first

http://gerrit.openvpn.net/c/openvpn/+/739/comment/babf9754_f9b70e73 :
PS3, Line 7037: if (cidr && !no_more_than_n_args(msglevel, p, 4, NM_QUOTE_HINT))
Why NM_QUOTE_HINT?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/e96e9d33_aa4c39e3 :
PS3, Line 7042: OPT_P_ROUTE
VERIFY_PERMISSION should go first

http://gerrit.openvpn.net/c/openvpn/+/739/comment/1c383a62_67435f56 :
PS3, Line 7047: const char *network = strtok(p[i++], "/"); /* this modifies p[1] */
I find this very ugly. Would be better if we could improve ip_or_dns_addr_safe to handle CIDR notation, wouldn't it?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/4bb91f0f_a5b37ba7 :
PS3, Line 7071: add_route_to_option_list(options->routes, p[1], NULL, p[2], p[3]);
Should we consider already normalizing the route here already and not parse the netmask vs netbits later _again_? But I have to confess I'm not sure why we store the strings here in the first place and do not parse them already, so I might be missing something.

http://gerrit.openvpn.net/c/openvpn/+/739/comment/70b69c9f_0e173b5d :
PS3, Line 7409: if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))
Why NM_QUOTE_HINT?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/eed071e7_4e1a613b :
PS3, Line 7424: msg(M_USAGE, "--server directive network/netmask combination is invalid");
Why does this have a separate error message here but not in the sameish code in --server-bridge below? Can probably remove it here.

http://gerrit.openvpn.net/c/openvpn/+/739/comment/ef3a007f_b7b2f353 :
PS3, Line 7487: if (!no_more_than_n_args(msglevel, p, 4, NM_QUOTE_HINT))
Why NM_QUOTE_HINT? Which argument could contain spaces?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/5a041385_78596de3 :
PS3, Line 7898: if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))
Why NM_QUOTE_HINT?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Fri, 13 Sep 2024 13:57:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>
Gerrit-MessageType: comment

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 3:

(12 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/af57c291_7928346b :
PS3, Line 9: Add support for CIDR notation on all suitable options (client-nat,
Maybe give some more motivation here. Why is this good for users? Is the assumption that this notation is easier to use for users?

Patchset:

PS3:
Finished with first pass over the whole change.

File src/openvpn/route.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/442c7c8d_d509e97e :
PS3, Line 324: const in_addr_t default_netbits = IPV4_NETBITS_HOST;
unsigned int?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/49b38146_172bf62a :
PS3, Line 331: const char *cidr = strchr(network, '/');
Would convert to bool here to make it clear purpose

http://gerrit.openvpn.net/c/openvpn/+/739/comment/9927b3a3_4809d0a7 :
PS3, Line 347: convert
Want to do a drive-by fix? "a a" -> "to an"?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/86ce371b_4860dec8 :
PS3, Line 1105: route
Maybe add a 0.0.0.0/1 and 128.0.0.0/1 to the comments just to make it slightly easier to read?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/f88439ab_4ecf8430 :
PS3, Line 1166: route (
Same (0.0.0.0/1 and 128.0.0.0/1) here.

http://gerrit.openvpn.net/c/openvpn/+/739/comment/77dbbd70_ab423838 :
PS3, Line 1456:
Maybe we could move this into the if block? Not sure why we would create it otherwise?

File src/openvpn/tun.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/cbb88db5_f07c3af6 :
PS3, Line 512: const bool looks_like_netmask = addr && ((addr & 0xFF000000) == 0xFF000000);
Isn't this redundant? If addr is 0 the second part never matches anyway

http://gerrit.openvpn.net/c/openvpn/+/739/comment/79c39edc_b5bdb970 :
PS3, Line 524:
Shouldn't that be "&&" ?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/e80071f2_d2431db9 :
PS3, Line 562: const in_addr_t public_net = public &netmask;
Add space after & ?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/7d0d0823_03c88869 :
PS3, Line 591: &
Add space after &

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Mon, 16 Sep 2024 12:39:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 3:

(25 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/ef955895_c40062c5 :
PS3, Line 9: Add support for CIDR notation on all suitable options (client-nat,

Quoted 1 line

Maybe give some more motivation here. […]

Acknowledged

File doc/man-sections/server-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/36991047_c59736fd :
PS3, Line 344: :code:255.255.255.255.

Quoted 1 line

for completeness mentions /32 as well.

Acknowledged

File doc/man-sections/vpn-network-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/61768e6b_7acc98ad :
PS3, Line 220: ifconfig local rn

Quoted 1 line

Need to specify the two possibilities (IP address or netmask) separately. […]

I think it stands for remote_netmask. I left it like this because I found it mentioned in this form in the explanation that follows (line 237) but I agree it isn't clear. I'm duplicating it to show both versions of ifconfig (remote and netmask) as you suggested. However this may not be completely coherent to --ifconfig-push (which has "local remote-netmask" arguments). Should I change that one too accordingly?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/308f35e0_f16ee639 :
PS3, Line 266: 2 255

Quoted 1 line

Add /bits example here?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/1861ac78_b520ac5c :
PS3, Line 389: route network|ipv4addr [netmask] [gateway] [metric]

Quoted 1 line

Does the network|ipv4addr here really add any value? Should we go just for ipv4addr here like with - […]

I didn't drop the "network" format because I thought it was referring to the DNS resolvable name or special keywords as opposed to the ipv4 address. But I see that it can be a bit misleading therefore I will duplicate the lines (network and ipv4addr).

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/ce30cce3_6ee36c90 :
PS3, Line 6103: if (!p[2]) /* p[1] must be in CIDR format */

Quoted 1 line

Should probably do a ip_or_dns_addr_safe(p[1]) here? Might need to enhance that function to allow ne […]

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/10b9fbdb_8c9a2ae0 :
PS3, Line 7029: VERIFY_PERMISSION

Quoted 1 line

VERIFY_PERMISSION should go first

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/b4a5b082_b11cfef8 :
PS3, Line 7037: if (cidr && !no_more_than_n_args(msglevel, p, 4, NM_QUOTE_HINT))

Quoted 1 line

Why NM_QUOTE_HINT?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/4c4dea4c_37ac9b94 :
PS3, Line 7042: OPT_P_ROUTE

Quoted 1 line

VERIFY_PERMISSION should go first

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/23a2b49a_8cb1624d :
PS3, Line 7047: const char *network = strtok(p[i++], "/"); /* this modifies p[1] */

Quoted 1 line

I find this very ugly. […]

Yes, definitely.

http://gerrit.openvpn.net/c/openvpn/+/739/comment/1f3bc400_01968578 :
PS3, Line 7071: add_route_to_option_list(options->routes, p[1], NULL, p[2], p[3]);

Quoted 1 line

Should we consider already normalizing the route here already and not parse the netmask vs netbits l […]

The parameters are all stored in string format because "network" and "gateway" can be ip addresses, resolvable names or even special keywords and the parsing is done in init_route(). If we were to search for the netbits here (in order to convert them into a netmask or vice versa) we would end up moving some of the init_route() logic here. Anyway, once ip_or_dns_addr_safe() is improved to handle CIDR notated addresses, do you still think the overhead introduced here is too much?

http://gerrit.openvpn.net/c/openvpn/+/739/comment/03dc6477_3baf4f59 :
PS3, Line 7409: if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))

Quoted 1 line

Why NM_QUOTE_HINT?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/c67b2950_32857d05 :
PS3, Line 7424: msg(M_USAGE, "--server directive network/netmask combination is invalid");

Quoted 1 line

Why does this have a separate error message here but not in the sameish code in --server-bridge belo […]

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/68375742_e67a2168 :
PS3, Line 7487: if (!no_more_than_n_args(msglevel, p, 4, NM_QUOTE_HINT))

Quoted 1 line

Why NM_QUOTE_HINT? Which argument could contain spaces?

None in fact, I just totally overlooked this flags honestly. Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/600e6ed7_2f6ddc3f :
PS3, Line 7898: if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))

Quoted 1 line

Why NM_QUOTE_HINT?

Acknowledged

File src/openvpn/route.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/ac8b37af_6f6e9a74 :
PS3, Line 324: const in_addr_t default_netbits = IPV4_NETBITS_HOST;

Quoted 1 line

unsigned int?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/ee1f7533_80da73d9 :
PS3, Line 331: const char *cidr = strchr(network, '/');

Quoted 1 line

Would convert to bool here to make it clear purpose

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/1b593f21_ba11a0bc :
PS3, Line 347: convert

Quoted 1 line

Want to do a drive-by fix? "a a" -> "to an"?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/fcdc0ae1_bb844192 :
PS3, Line 1105: route

Quoted 1 line

Maybe add a 0.0.0.0/1 and 128.0.0. […]

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/3eb2716e_74185bc0 :
PS3, Line 1166: route (

Quoted 1 line

Same (0.0.0.0/1 and 128.0.0.0/1) here.

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/2e313668_5df0fac8 :
PS3, Line 1456:

Quoted 1 line

Maybe we could move this into the if block? Not sure why we would create it otherwise?

Acknowledged

File src/openvpn/tun.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/6a23e054_db476467 :
PS3, Line 512: const bool looks_like_netmask = addr && ((addr & 0xFF000000) == 0xFF000000);

Quoted 1 line

Isn't this redundant? If addr is 0 the second part never matches anyway

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/fe64f694_ae441e6d :
PS3, Line 524:

Quoted 1 line

Shouldn't that be "&&" ?

Yes, indeed

http://gerrit.openvpn.net/c/openvpn/+/739/comment/a2797ec0_d79ee4f7 :
PS3, Line 562: const in_addr_t public_net = public &netmask;

Quoted 1 line

Add space after & ?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/7d21b2d6_5f6efde8 :
PS3, Line 591: &

Quoted 1 line

Add space after &

Acknowledged

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 16 Sep 2024 15:54:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#11 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 4: -Code-Review

(1 comment)

File doc/man-sections/vpn-network-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/010562e7_9eb9bcd4 :
PS3, Line 220: ifconfig local rn

Quoted 1 line

I think it stands for remote_netmask. […]

Yes, I think that is a good idea.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 4
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Sep 2024 11:34:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>
Gerrit-MessageType: comment

#12 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 4:

(1 comment)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/fc1038c9_4e579e2c :
PS3, Line 7071: add_route_to_option_list(options->routes, p[1], NULL, p[2], p[3]);

Quoted 1 line

The parameters are all stored in string format because "network" and "gateway" can be ip addresses, […]

yeah, it is fine. More idle wondering. If we ever decide to refactor that, that is probably worth its own patch series ;)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 4
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Sep 2024 11:37:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>
Gerrit-MessageType: comment

#13 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 4:

(1 comment)

File src/openvpn/tun.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/b961361b_51671575 :
PS4, Line 559: const in_addr_t public_net = public & netmask;
Turns out, it was formatted wrong because uncrustify thinks "public" is a keyword and not a variable. Renaming it should fix that.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 4
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Sep 2024 11:39:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#14 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 5:

(3 comments)

File doc/man-sections/vpn-network-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/e9b1f04d_20390532 :
PS3, Line 220: ifconfig local rn

Quoted 1 line

Yes, I think that is a good idea.

Done

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/4b0a66fc_21822d3b :
PS3, Line 7071: add_route_to_option_list(options->routes, p[1], NULL, p[2], p[3]);

Quoted 1 line

yeah, it is fine. More idle wondering. […]

Acknowledged

File src/openvpn/tun.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/0d09b12f_5f27c1f4 :
PS4, Line 559: const in_addr_t public_net = public & netmask;

Quoted 1 line

Turns out, it was formatted wrong because uncrustify thinks "public" is a keyword and not a variable […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 5
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Sep 2024 16:12:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>
Gerrit-MessageType: comment

#15 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 5: Code-Review-1

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/6d4da998_8fb1e742 :
PS5, Line 741: const char *sep = strchrnul(addr, '/');
strchrnul() is a GNU invention and breaks build on OpenBSD and macOS.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 5
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Sep 2024 10:11:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#16 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: Support CIDR on options and extend netbits usage
......................................................................

Patch Set 6:

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/77c42bbf_3459ccce :
PS5, Line 741: const char *sep = strchrnul(addr, '/');

Quoted 1 line

strchrnul() is a GNU invention and breaks build on OpenBSD and macOS.

Done. Switched to strchr().

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 6
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Sep 2024 10:56:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#17 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#8).

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

options: add IPv4 CIDR parsing for relevant directives

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M doc/man-sections/client-options.rst
M doc/man-sections/server-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M tests/unit_tests/openvpn/test_options_parse.c

7 files changed, 486 insertions(+), 77 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/8

doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +32 -15

90 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +163 -33

348 lines not on this page · raw message

src/openvpn/options_util.c +94 -0

100 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/test_options_parse.c +133 -14

171 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 8
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#18 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

Patch Set 9: Code-Review-1

(5 comments)

File doc/man-sections/server-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/6c774407_c41b8c34?usp=email :
PS9, Line 309: view.
I would find it a bit easier to read if this was more explicit. Maybe add something like "So the server will actually push ``ifconfig alias remote/netmask`` to the client"?

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/35d57942_8451aec7?usp=email :
PS9, Line 7288: const int lev = M_WARN;
Please fix to msglvl_t

http://gerrit.openvpn.net/c/openvpn/+/739/comment/9c9d016a_9cface99?usp=email :
PS9, Line 7688: remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, ifconfig_push_parms[2], 0,
A bit absurd that we need to parse netmask here again if we generated it before. But probably not worth trying to optimize that away.

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/8d1749e3_5a891d4c?usp=email :
PS9, Line 232: * socket_util.c dependencies into options_util unit-test targets. */
This feels like a weak justification to duplicate code.

File tests/unit_tests/openvpn/test_options_parse.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/ab0e93b7_3d53fbba?usp=email :
PS9, Line 330: test_convert_ipv4_cidr_parms_coverage(void **state)
This does not feel like it provides actual "coverage". The examples are all too similar. To get coverage you should test a bigger variety of "bits" (maybe throw a "0" and a "32" in there at least?) and more interesting variants of input parameters (even if they are not currently realistic). E.g. use minimal and maximal values for network_idx and max_idx.

Also include the case where the network parameter is a DNS name

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 9
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Mon, 09 Mar 2026 13:10:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#19 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

Patch Set 9:

(5 comments)

File doc/man-sections/server-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/93ccbb1c_e6347e78?usp=email :
PS9, Line 309: view.

Quoted 1 line

I would find it a bit easier to read if this was more explicit. […]

Acknowledged

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/bc6ae7da_894ede5f?usp=email :
PS9, Line 7288: const int lev = M_WARN;

Quoted 1 line

Please fix to msglvl_t

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/739/comment/25bbf8a6_50aad5ce?usp=email :
PS9, Line 7688: remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, ifconfig_push_parms[2], 0,

Quoted 1 line

A bit absurd that we need to parse netmask here again if we generated it before. […]

I agree. The main issue is that IPv4 options in options.c do not all convert at the same stage: some paths keep parameters as strings until later consumers, while others parse to binary earlier. A dual-helper design (string + binary outputs) is possible, but it would either duplicate per-option handling or require a broader parsing abstraction.
For this change, the scope is limited to translating CIDR-form IPv4 parameter strings into the existing legacy string form, without altering downstream option processing.

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/eb44c41a_68747e58?usp=email :
PS9, Line 232: * socket_util.c dependencies into options_util unit-test targets. */

Quoted 1 line

This feels like a weak justification to duplicate code.

Just to make sure I understood this point correctly: do you prefer that I switch to print_in_addr_t() (and pull in socket_util dependencies), or that I keep the local conversion and only tighten/remove the justification comment?
I tried the former locally: switching to print_in_addr_t() made options_parse_testdriver, push_update_msg_testdriver, and misc_testdriver fail to link unless socket_util.c is also linked. Once socket_util.c is linked, additional transitive symbols are required (setenv_*, siginfo_static/signal_reset, management_*), so this becomes a broader test/build refactor. That's why for this patch I kept the conversion self-contained in options_util.c.

File tests/unit_tests/openvpn/test_options_parse.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/306d8e15_e3a09146?usp=email :
PS9, Line 330: test_convert_ipv4_cidr_parms_coverage(void **state)

Quoted 1 line

This does not feel like it provides actual "coverage". The examples are all too similar. […]

Acknowledged

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 9
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 10 Mar 2026 09:53:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>

#20 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

Patch Set 9:

(2 comments)

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/c0e57a84_9a30f6b2?usp=email :
PS9, Line 7688: remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, ifconfig_push_parms[2], 0,

Quoted 1 line

I agree. The main issue is that IPv4 options in options. […]

Acknowledged

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/dc618575_003b428a?usp=email :
PS9, Line 232: * socket_util.c dependencies into options_util unit-test targets. */

Quoted 1 line

Just to make sure I understood this point correctly: do you prefer that I switch to print_in_addr_t( […]

Okay, to be clear: My opinion is that this code should not be duplicated. I think it is complicated enough that we should avoid this.

The UT changes are probably not actually a problem. The list of dependencies of test_socket is also reasonably small so I can't imagine this will be a complicated addition to test_options.

If that turns out to be wrong we could also look into whether moving the code to options_util would be simpler. There is no strict reason why it needs to be in socket_util.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 9
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Tue, 10 Mar 2026 10:28:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>

#21 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos, ralf_lici.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#10).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

options: add IPv4 CIDR parsing for relevant directives

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M doc/man-sections/client-options.rst
M doc/man-sections/server-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/mock_setenv.c
A tests/unit_tests/openvpn/mock_signal.c
M tests/unit_tests/openvpn/test_options_parse.c

10 files changed, 647 insertions(+), 82 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/10

doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +33 -15

91 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +168 -38

374 lines not on this page · raw message

src/openvpn/options_util.c +91 -0

103 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/Makefile.am +14 -0
index 1128eb4..bc29c99 100644
@@ -102,6 +102,7 @@
 ssl_testdriver_SOURCES = test_ssl.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_management.c \
+	mock_signal.c \
 	mock_ssl_dependencies.c mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
@@ -121,6 +122,7 @@
 	$(top_srcdir)/src/openvpn/packet_id.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/run_command.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/ssl_openssl.c \
 	$(top_srcdir)/src/openvpn/ssl_mbedtls.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
@@ -225,9 +227,13 @@
 options_parse_testdriver_SOURCES = test_options_parse.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/options_parse.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/openvpn/platform.c
 
@@ -370,7 +376,11 @@
 misc_testdriver_SOURCES = test_misc.c \
 	mock_msg.c test_common.h  \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
@@ -389,10 +399,14 @@
 push_update_msg_testdriver_SOURCES = test_push_update_msg.c \
 	mock_msg.c \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/otime.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/list.c
 
 socket_testdriver_CFLAGS  = \
tests/unit_tests/openvpn/mock_setenv.c new file +39 -0
new file mode 100644
index 0000000..a35a295
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "env_set.h"
+
+void
+setenv_str(struct env_set *es, const char *name, const char *value)
+{
+}
+
+void
+setenv_int(struct env_set *es, const char *name, int value)
+{
+}
tests/unit_tests/openvpn/mock_signal.c new file +37 -0
new file mode 100644
index 0000000..6a9bb05
@@ -0,0 +1,37 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "socket.h"
+
+struct signal_info siginfo_static; /* GLOBAL */
+
+int
+signal_reset(struct signal_info *si, int signum)
+{
+    return signum;
+}
tests/unit_tests/openvpn/test_options_parse.c +201 -14

239 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 10
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>

#22 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

Patch Set 10:

(1 comment)

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/739/comment/3152c2da_f44cfb55?usp=email :
PS9, Line 232: * socket_util.c dependencies into options_util unit-test targets. */

Quoted 1 line

Okay, to be clear: My opinion is that this code should not be duplicated. […]

Done. I used two minimal shared mocks (mock_signal.c, mock_setenv.c) for transitive symbols.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 10
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 10 Mar 2026 16:18:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ralf_lici <[email protected]...>

#23 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#11).

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

options: add IPv4 CIDR parsing for relevant directives

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M CMakeLists.txt
M doc/man-sections/client-options.rst
M doc/man-sections/server-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/mock_setenv.c
A tests/unit_tests/openvpn/mock_signal.c
M tests/unit_tests/openvpn/test_options_parse.c

11 files changed, 667 insertions(+), 82 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/11

CMakeLists.txt +18 -0
index 198c98f..5ce044b 100644
@@ -778,6 +778,7 @@
 
     target_sources(test_ssl PRIVATE
             tests/unit_tests/openvpn/mock_management.c
+            tests/unit_tests/openvpn/mock_signal.c
             tests/unit_tests/openvpn/mock_ssl_dependencies.c
             tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
@@ -794,6 +795,7 @@
             src/openvpn/otime.c
             src/openvpn/packet_id.c
             src/openvpn/run_command.c
+            src/openvpn/socket_util.c
             src/openvpn/ssl_mbedtls.c
             src/openvpn/ssl_openssl.c
             src/openvpn/ssl_util.c
@@ -802,6 +804,7 @@
             src/openvpn/xkey_helper.c
             src/openvpn/xkey_provider.c
     )
+    target_link_libraries(test_ssl PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_mbuf PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -811,10 +814,15 @@
 
     target_sources(test_misc PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         src/openvpn/ssl_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_misc PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_ncp PRIVATE
         src/openvpn/crypto_epoch.c
@@ -829,9 +837,14 @@
 
     target_sources(test_options_parse PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_parse.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         )
+    target_link_libraries(test_options_parse PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_packet_id PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -888,10 +901,15 @@
     target_sources(test_push_update_msg PRIVATE
         tests/unit_tests/openvpn/mock_msg.c
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
         src/openvpn/otime.c
+        src/openvpn/socket_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_push_update_msg PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_argv PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +33 -15

91 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +168 -38

374 lines not on this page · raw message

src/openvpn/options_util.c +91 -0

103 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/Makefile.am +14 -0
index 1128eb4..bc29c99 100644
@@ -102,6 +102,7 @@
 ssl_testdriver_SOURCES = test_ssl.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_management.c \
+	mock_signal.c \
 	mock_ssl_dependencies.c mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
@@ -121,6 +122,7 @@
 	$(top_srcdir)/src/openvpn/packet_id.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/run_command.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/ssl_openssl.c \
 	$(top_srcdir)/src/openvpn/ssl_mbedtls.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
@@ -225,9 +227,13 @@
 options_parse_testdriver_SOURCES = test_options_parse.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/options_parse.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/openvpn/platform.c
 
@@ -370,7 +376,11 @@
 misc_testdriver_SOURCES = test_misc.c \
 	mock_msg.c test_common.h  \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
@@ -389,10 +399,14 @@
 push_update_msg_testdriver_SOURCES = test_push_update_msg.c \
 	mock_msg.c \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/otime.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/list.c
 
 socket_testdriver_CFLAGS  = \
tests/unit_tests/openvpn/mock_setenv.c new file +39 -0
new file mode 100644
index 0000000..a35a295
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "env_set.h"
+
+void
+setenv_str(struct env_set *es, const char *name, const char *value)
+{
+}
+
+void
+setenv_int(struct env_set *es, const char *name, int value)
+{
+}
tests/unit_tests/openvpn/mock_signal.c new file +39 -0
new file mode 100644
index 0000000..b88d1a3
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "socket.h"
+
+#ifndef _WIN32
+struct signal_info siginfo_static; /* GLOBAL */
+#endif
+
+int
+signal_reset(struct signal_info *si, int signum)
+{
+    return signum;
+}
tests/unit_tests/openvpn/test_options_parse.c +201 -14

239 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 11
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#24 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#12).

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

options: add IPv4 CIDR parsing for relevant directives

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M CMakeLists.txt
M doc/man-sections/client-options.rst
M doc/man-sections/server-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/mock_setenv.c
A tests/unit_tests/openvpn/mock_signal.c
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_ssl.c

12 files changed, 675 insertions(+), 84 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/12

CMakeLists.txt +18 -0
index 198c98f..5ce044b 100644
@@ -778,6 +778,7 @@
 
     target_sources(test_ssl PRIVATE
             tests/unit_tests/openvpn/mock_management.c
+            tests/unit_tests/openvpn/mock_signal.c
             tests/unit_tests/openvpn/mock_ssl_dependencies.c
             tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
@@ -794,6 +795,7 @@
             src/openvpn/otime.c
             src/openvpn/packet_id.c
             src/openvpn/run_command.c
+            src/openvpn/socket_util.c
             src/openvpn/ssl_mbedtls.c
             src/openvpn/ssl_openssl.c
             src/openvpn/ssl_util.c
@@ -802,6 +804,7 @@
             src/openvpn/xkey_helper.c
             src/openvpn/xkey_provider.c
     )
+    target_link_libraries(test_ssl PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_mbuf PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -811,10 +814,15 @@
 
     target_sources(test_misc PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         src/openvpn/ssl_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_misc PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_ncp PRIVATE
         src/openvpn/crypto_epoch.c
@@ -829,9 +837,14 @@
 
     target_sources(test_options_parse PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_parse.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         )
+    target_link_libraries(test_options_parse PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_packet_id PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -888,10 +901,15 @@
     target_sources(test_push_update_msg PRIVATE
         tests/unit_tests/openvpn/mock_msg.c
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
         src/openvpn/otime.c
+        src/openvpn/socket_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_push_update_msg PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_argv PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +33 -15

91 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +168 -38

374 lines not on this page · raw message

src/openvpn/options_util.c +91 -0

103 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/Makefile.am +14 -0
index 1128eb4..bc29c99 100644
@@ -102,6 +102,7 @@
 ssl_testdriver_SOURCES = test_ssl.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_management.c \
+	mock_signal.c \
 	mock_ssl_dependencies.c mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
@@ -121,6 +122,7 @@
 	$(top_srcdir)/src/openvpn/packet_id.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/run_command.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/ssl_openssl.c \
 	$(top_srcdir)/src/openvpn/ssl_mbedtls.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
@@ -225,9 +227,13 @@
 options_parse_testdriver_SOURCES = test_options_parse.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/options_parse.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/openvpn/platform.c
 
@@ -370,7 +376,11 @@
 misc_testdriver_SOURCES = test_misc.c \
 	mock_msg.c test_common.h  \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
@@ -389,10 +399,14 @@
 push_update_msg_testdriver_SOURCES = test_push_update_msg.c \
 	mock_msg.c \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/otime.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/list.c
 
 socket_testdriver_CFLAGS  = \
tests/unit_tests/openvpn/mock_setenv.c new file +39 -0
new file mode 100644
index 0000000..a35a295
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "env_set.h"
+
+void
+setenv_str(struct env_set *es, const char *name, const char *value)
+{
+}
+
+void
+setenv_int(struct env_set *es, const char *name, int value)
+{
+}
tests/unit_tests/openvpn/mock_signal.c new file +47 -0

47 lines not on this page · raw message

tests/unit_tests/openvpn/test_options_parse.c +201 -14

239 lines not on this page · raw message

tests/unit_tests/openvpn/test_ssl.c +0 -2
index 2b73ee7..9182cb8 100644
@@ -51,8 +51,6 @@
 /* Mock function to be allowed to include win32.c which is required for
  * getting the temp directory */
 #ifdef _WIN32
-struct signal_info siginfo_static; /* GLOBAL */
-
 const char *
 strerror_win32(DWORD errnum, struct gc_arena *gc)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 12
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#25 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#13).

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

options: add IPv4 CIDR parsing for relevant directives

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M CMakeLists.txt
M doc/man-sections/client-options.rst
M doc/man-sections/server-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/mock_setenv.c
A tests/unit_tests/openvpn/mock_signal.c
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_ssl.c

12 files changed, 680 insertions(+), 87 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/13

CMakeLists.txt +18 -0
index 198c98f..5ce044b 100644
@@ -778,6 +778,7 @@
 
     target_sources(test_ssl PRIVATE
             tests/unit_tests/openvpn/mock_management.c
+            tests/unit_tests/openvpn/mock_signal.c
             tests/unit_tests/openvpn/mock_ssl_dependencies.c
             tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
@@ -794,6 +795,7 @@
             src/openvpn/otime.c
             src/openvpn/packet_id.c
             src/openvpn/run_command.c
+            src/openvpn/socket_util.c
             src/openvpn/ssl_mbedtls.c
             src/openvpn/ssl_openssl.c
             src/openvpn/ssl_util.c
@@ -802,6 +804,7 @@
             src/openvpn/xkey_helper.c
             src/openvpn/xkey_provider.c
     )
+    target_link_libraries(test_ssl PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_mbuf PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -811,10 +814,15 @@
 
     target_sources(test_misc PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         src/openvpn/ssl_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_misc PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_ncp PRIVATE
         src/openvpn/crypto_epoch.c
@@ -829,9 +837,14 @@
 
     target_sources(test_options_parse PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_parse.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         )
+    target_link_libraries(test_options_parse PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_packet_id PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -888,10 +901,15 @@
     target_sources(test_push_update_msg PRIVATE
         tests/unit_tests/openvpn/mock_msg.c
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
         src/openvpn/otime.c
+        src/openvpn/socket_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_push_update_msg PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_argv PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +33 -15

91 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +168 -38

374 lines not on this page · raw message

src/openvpn/options_util.c +91 -0

103 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/Makefile.am +19 -3
index 1128eb4..1e5aa59 100644
@@ -102,6 +102,7 @@
 ssl_testdriver_SOURCES = test_ssl.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_management.c \
+	mock_signal.c \
 	mock_ssl_dependencies.c mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
@@ -121,6 +122,7 @@
 	$(top_srcdir)/src/openvpn/packet_id.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/run_command.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/ssl_openssl.c \
 	$(top_srcdir)/src/openvpn/ssl_mbedtls.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
@@ -221,13 +223,18 @@
 endif
 
 options_parse_testdriver_CFLAGS  = -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat @TEST_CFLAGS@
-options_parse_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn
+options_parse_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn \
+	$(SOCKETS_LIBS)
 options_parse_testdriver_SOURCES = test_options_parse.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/options_parse.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/openvpn/platform.c
 
@@ -365,12 +372,16 @@
 	-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \
 	-DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
 
-misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
+misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ $(SOCKETS_LIBS)
 
 misc_testdriver_SOURCES = test_misc.c \
 	mock_msg.c test_common.h  \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
@@ -384,15 +395,20 @@
 
 push_update_msg_testdriver_LDFLAGS = \
 	@TEST_LDFLAGS@ \
-	-L$(top_srcdir)/src/openvpn
+	-L$(top_srcdir)/src/openvpn \
+	$(SOCKETS_LIBS)
 
 push_update_msg_testdriver_SOURCES = test_push_update_msg.c \
 	mock_msg.c \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/otime.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/list.c
 
 socket_testdriver_CFLAGS  = \
tests/unit_tests/openvpn/mock_setenv.c new file +39 -0
new file mode 100644
index 0000000..a35a295
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "env_set.h"
+
+void
+setenv_str(struct env_set *es, const char *name, const char *value)
+{
+}
+
+void
+setenv_int(struct env_set *es, const char *name, int value)
+{
+}
tests/unit_tests/openvpn/mock_signal.c new file +47 -0

47 lines not on this page · raw message

tests/unit_tests/openvpn/test_options_parse.c +201 -14

239 lines not on this page · raw message

tests/unit_tests/openvpn/test_ssl.c +0 -2
index 2b73ee7..9182cb8 100644
@@ -51,8 +51,6 @@
 /* Mock function to be allowed to include win32.c which is required for
  * getting the temp directory */
 #ifdef _WIN32
-struct signal_info siginfo_static; /* GLOBAL */
-
 const char *
 strerror_win32(DWORD errnum, struct gc_arena *gc)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 13
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#26 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/739?usp=email

to look at the new patch set (#14).

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

options: add IPv4 CIDR parsing for relevant directives

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

---
M CMakeLists.txt
M doc/man-sections/client-options.rst
M doc/man-sections/server-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/mock_setenv.c
A tests/unit_tests/openvpn/mock_signal.c
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_ssl.c

12 files changed, 681 insertions(+), 88 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/739/14

CMakeLists.txt +18 -0
index 198c98f..5ce044b 100644
@@ -778,6 +778,7 @@
 
     target_sources(test_ssl PRIVATE
             tests/unit_tests/openvpn/mock_management.c
+            tests/unit_tests/openvpn/mock_signal.c
             tests/unit_tests/openvpn/mock_ssl_dependencies.c
             tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
@@ -794,6 +795,7 @@
             src/openvpn/otime.c
             src/openvpn/packet_id.c
             src/openvpn/run_command.c
+            src/openvpn/socket_util.c
             src/openvpn/ssl_mbedtls.c
             src/openvpn/ssl_openssl.c
             src/openvpn/ssl_util.c
@@ -802,6 +804,7 @@
             src/openvpn/xkey_helper.c
             src/openvpn/xkey_provider.c
     )
+    target_link_libraries(test_ssl PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_mbuf PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -811,10 +814,15 @@
 
     target_sources(test_misc PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         src/openvpn/ssl_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_misc PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_ncp PRIVATE
         src/openvpn/crypto_epoch.c
@@ -829,9 +837,14 @@
 
     target_sources(test_options_parse PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_parse.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         )
+    target_link_libraries(test_options_parse PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_packet_id PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -888,10 +901,15 @@
     target_sources(test_push_update_msg PRIVATE
         tests/unit_tests/openvpn/mock_msg.c
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
         src/openvpn/otime.c
+        src/openvpn/socket_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_push_update_msg PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_argv PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +33 -15

91 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +168 -38

374 lines not on this page · raw message

src/openvpn/options_util.c +91 -0

103 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/Makefile.am +20 -4
index 1128eb4..e277d40 100644
@@ -98,10 +98,11 @@
 ssl_testdriver_CFLAGS  = \
 	-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \
 	@TEST_CFLAGS@
-ssl_testdriver_LDFLAGS = @TEST_LDFLAGS@  $(OPTIONAL_CRYPTO_LIBS)
+ssl_testdriver_LDFLAGS = @TEST_LDFLAGS@  $(OPTIONAL_CRYPTO_LIBS) $(SOCKETS_LIBS)
 ssl_testdriver_SOURCES = test_ssl.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_management.c \
+	mock_signal.c \
 	mock_ssl_dependencies.c mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
@@ -121,6 +122,7 @@
 	$(top_srcdir)/src/openvpn/packet_id.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/run_command.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/ssl_openssl.c \
 	$(top_srcdir)/src/openvpn/ssl_mbedtls.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
@@ -221,13 +223,18 @@
 endif
 
 options_parse_testdriver_CFLAGS  = -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat @TEST_CFLAGS@
-options_parse_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn
+options_parse_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn \
+	$(SOCKETS_LIBS)
 options_parse_testdriver_SOURCES = test_options_parse.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/options_parse.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/openvpn/platform.c
 
@@ -365,12 +372,16 @@
 	-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \
 	-DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
 
-misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
+misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ $(SOCKETS_LIBS)
 
 misc_testdriver_SOURCES = test_misc.c \
 	mock_msg.c test_common.h  \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
@@ -384,15 +395,20 @@
 
 push_update_msg_testdriver_LDFLAGS = \
 	@TEST_LDFLAGS@ \
-	-L$(top_srcdir)/src/openvpn
+	-L$(top_srcdir)/src/openvpn \
+	$(SOCKETS_LIBS)
 
 push_update_msg_testdriver_SOURCES = test_push_update_msg.c \
 	mock_msg.c \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/otime.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/list.c
 
 socket_testdriver_CFLAGS  = \
tests/unit_tests/openvpn/mock_setenv.c new file +39 -0
new file mode 100644
index 0000000..a35a295
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "env_set.h"
+
+void
+setenv_str(struct env_set *es, const char *name, const char *value)
+{
+}
+
+void
+setenv_int(struct env_set *es, const char *name, int value)
+{
+}
tests/unit_tests/openvpn/mock_signal.c new file +47 -0

47 lines not on this page · raw message

tests/unit_tests/openvpn/test_options_parse.c +201 -14

239 lines not on this page · raw message

tests/unit_tests/openvpn/test_ssl.c +0 -2
index 2b73ee7..9182cb8 100644
@@ -51,8 +51,6 @@
 /* Mock function to be allowed to include win32.c which is required for
  * getting the temp directory */
 #ifdef _WIN32
-struct signal_info siginfo_static; /* GLOBAL */
-
 const char *
 strerror_win32(DWORD errnum, struct gc_arena *gc)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 14
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#27 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/739?usp=email )

Change subject: options: add IPv4 CIDR parsing for relevant directives
......................................................................

Patch Set 14: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iae04ad8715e40dfc76475c2c5b9a766c9604efc9
Gerrit-Change-Number: 739
Gerrit-PatchSet: 14
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Mar 2026 15:32:05 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#28 lore raw

PATCH v14 1/1 options: add IPv4 CIDR parsing for relevant directives

In reply to a message not in the archive

From: Ralf Lici <[email protected]...>

Add support for CIDR notation on all suitable options (client-nat, ifconfig, ifconfig-push, ifconfig-push-constraint, iroute, route, server, server-bridge). This change provides a more consistent approach for users already familiar with CIDR notation and simplifies network configuration in scenarios where IP ranges are more naturally expressed in CIDR form. It also allows for more compact OpenVPN configurations.

Static --push "..." payloads remain opaque by design (current policy), so CIDR normalization is not applied to those strings.

Due to current PUSH_UPDATE plumbing, option payloads are only parsed/validated when processed in update_option (after transmission), so this change normalizes CIDR there but does not introduce pre-send payload rewriting/validation as that would require a rework of the PUSH_UPDATE architecture. This also means compatibility is not guaranteed for PUSH_UPDATE-capable peers that do not parse CIDR: the sender can accept a CIDR-formatted PUSH_UPDATE as valid after sending it, while a PUSH_UPDATE-capable peer that does not parse CIDR may reject it; this can leave sender and receiver with diverging effective state.

Internal behavior remains netmask-based, and existing netmask environment variables are unchanged.

Tests for CIDR parsing and option normalization are added in test_options_parse.c covering all affected options.

Change-Id Iae04ad8715e40dfc76475c2c5b9a766c9604efc9

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/739
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/739
This mail reflects revision 14 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

CMakeLists.txt +18 -0
index 198c98f..5ce044b 100644
@@ -778,6 +778,7 @@
 
     target_sources(test_ssl PRIVATE
             tests/unit_tests/openvpn/mock_management.c
+            tests/unit_tests/openvpn/mock_signal.c
             tests/unit_tests/openvpn/mock_ssl_dependencies.c
             tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
@@ -794,6 +795,7 @@
             src/openvpn/otime.c
             src/openvpn/packet_id.c
             src/openvpn/run_command.c
+            src/openvpn/socket_util.c
             src/openvpn/ssl_mbedtls.c
             src/openvpn/ssl_openssl.c
             src/openvpn/ssl_util.c
@@ -802,6 +804,7 @@
             src/openvpn/xkey_helper.c
             src/openvpn/xkey_provider.c
     )
+    target_link_libraries(test_ssl PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_mbuf PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -811,10 +814,15 @@
 
     target_sources(test_misc PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         src/openvpn/ssl_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_misc PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_ncp PRIVATE
         src/openvpn/crypto_epoch.c
@@ -829,9 +837,14 @@
 
     target_sources(test_options_parse PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_parse.c
         src/openvpn/options_util.c
+        src/openvpn/socket_util.c
         )
+    target_link_libraries(test_options_parse PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_packet_id PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
@@ -888,10 +901,15 @@
     target_sources(test_push_update_msg PRIVATE
         tests/unit_tests/openvpn/mock_msg.c
         tests/unit_tests/openvpn/mock_get_random.c
+        tests/unit_tests/openvpn/mock_management.c
+        tests/unit_tests/openvpn/mock_setenv.c
+        tests/unit_tests/openvpn/mock_signal.c
         src/openvpn/options_util.c
         src/openvpn/otime.c
+        src/openvpn/socket_util.c
         src/openvpn/list.c
         )
+    target_link_libraries(test_push_update_msg PUBLIC ${RESOLV_LIBRARIES})
 
     target_sources(test_argv PRIVATE
         tests/unit_tests/openvpn/mock_get_random.c
doc/man-sections/client-options.rst +8 -6
index 85d25e5..c47e90e 100644
@@ -132,21 +132,23 @@
   ifconfig settings pushed to the client would create an IP numbering
   conflict.
 
-  Valid syntax:
+  Valid syntaxes:
   ::
 
       client-nat snat|dnat network netmask alias
+      client-nat snat|dnat network/bits alias
 
   Examples:
   ::
 
       client-nat snat 192.168.0.0 255.255.0.0 10.64.0.0
-      client-nat dnat 10.64.0.0 255.255.0.0 192.168.0.0
+      client-nat dnat 10.64.0.0/16 192.168.0.0
 
-  ``network`` and ``netmask`` (for example :code:`192.168.0.0
-  255.255.0.0`) define the local view of a resource from the client
-  perspective, while ``alias`` (for example :code:`10.64.0.0`) defines the
-  remote view from the server perspective using the same netmask.
+  ``network netmask`` (for example :code:`192.168.0.0 255.255.0.0`) or
+  ``network/bits`` (for example :code:`192.168.0.0/16`) defines the local
+  view of a resource from the client perspective, while ``alias`` (for
+  example :code:`10.64.0.0`) defines the remote view from the server
+  perspective using the same netmask/bits.
 
   Use :code:`snat` (source NAT) for resources owned by the client and
   :code:`dnat` (destination NAT) for remote resources.
doc/man-sections/server-options.rst +33 -15

91 lines not on this page · raw message

doc/man-sections/vpn-network-options.rst +23 -9
index 33ebedb..27a61ed 100644
@@ -223,19 +223,28 @@
         Android 10 or later.
 
 --ifconfig args
+  Valid syntaxes:
+  ::
+
+     ifconfig local remote
+     ifconfig local netmask
+     ifconfig local/bits
+
   Set TUN/TAP adapter parameters. It requires the *IP address* of the local
   VPN endpoint. For TUN devices in point-to-point mode, the next argument
   must be the VPN IP address of the remote VPN endpoint. For TAP devices,
   or TUN devices used with ``--topology subnet``, the second argument
   is the subnet mask of the virtual network segment which is being created
-  or connected to.
+  or connected to. In this netmask case, ``local/bits`` may be used as a
+  compact form.
 
   For TUN devices, which facilitate virtual point-to-point IP connections
   (when used in ``--topology net30`` or ``p2p`` mode), the proper usage of
   ``--ifconfig`` is to use two private IP addresses which are not a member
-  of any existing subnet which is in use. The IP addresses may be
+  of any existing subnet which is in use. In this mode, use the explicit
+  ``local remote`` form (CIDR form is not applicable). The IP addresses may be
   consecutive and should have their order reversed on the remote peer.
-  After the VPN is established, by pinging ``rn``, you will be pinging
+  After the VPN is established, by pinging ``remote``, you will be pinging
   across the VPN.
 
   For TAP devices, which provide the ability to create virtual ethernet
@@ -267,6 +276,9 @@
      # tun/tap device in subnet mode
      ifconfig 10.8.0.2 255.255.255.0
 
+     # equivalent subnet-mode shorthand
+     ifconfig 10.8.0.2/24
+
 --ifconfig-ipv6 args
   Configure an IPv6 address on the *tun* device.
 
@@ -405,17 +417,16 @@
   Valid syntaxes:
   ::
 
-      route network/IP
-      route network/IP netmask
-      route network/IP netmask gateway
-      route network/IP netmask gateway metric
+      route network [netmask] [gateway] [metric]
+      route ipv4addr [netmask] [gateway] [metric]
+      route ipv4addr[/bits] [gateway] [metric]
 
   This option is intended as a convenience proxy for the ``route``\(8)
   shell command, while at the same time providing portable semantics
   across OpenVPN's platform space.
 
-  ``netmask``
-        defaults to :code:`255.255.255.255` when not given
+  ``netmask`` (or ``bits``)
+        defaults to :code:`255.255.255.255` (or :code:`/32`) when not given
 
   ``gateway``
         default taken from ``--route-gateway`` or the second
@@ -431,6 +442,9 @@
   DNS or :code:`/etc/hosts` file resolvable name, or as one of three special
   keywords:
 
+  The ``ipv4addr`` parameter may be specified using CIDR notation, thus
+  omitting the ``netmask`` parameter.
+
   :code:`vpn_gateway`
       The remote VPN endpoint address (derived either from
       ``--route-gateway`` or the second parameter to ``--ifconfig``
src/openvpn/options.c +168 -38

374 lines not on this page · raw message

src/openvpn/options_util.c +91 -0

103 lines not on this page · raw message

src/openvpn/options_util.h +33 -0
index 511d189..4c6ea3a 100644
@@ -108,4 +108,37 @@
  */
 bool check_push_update_option_flags(char *line, int *i, unsigned int *flags);
 
+/**
+ * Convert option parameters whose first IPv4 parameter may be in CIDR notation.
+ *
+ * The input tokens are read from \p p and the normalized output tokens are
+ * written to \p normalized.
+ *
+ * When \p p[network_idx] is in CIDR form (for example, ``10.8.0.0/24``), this
+ * function:
+ * - splits the network and prefix length,
+ * - converts the prefix length to dotted-quad netmask,
+ * - writes ``network`` and ``netmask`` into ``normalized[network_idx]`` and
+ *   ``normalized[network_idx + 1]``,
+ * - shifts remaining parameters one position to preserve legacy
+ *   ``network netmask ...`` layout.
+ *
+ * When \p p[network_idx] is not CIDR, \p normalized receives \p p unchanged
+ * for the copied range (indices ``0..max_idx`` until ``NULL``), and no
+ * conversion is applied.
+ *
+ * @param p Input option tokens (argv-style, NULL-terminated).
+ * @param network_idx Index in \p p of the parameter that may contain CIDR.
+ * @param max_idx Maximum parameter index to normalize.
+ * @param normalized Output token array receiving normalized parameters
+ *                   (argv-style, NULL-terminated in CIDR case).
+ * @param gc GC arena used for converted string allocations.
+ *
+ * @return 0 when no CIDR notation was present and no conversion was needed.
+ * @return 1 when CIDR notation was present and conversion was applied.
+ * @return -EINVAL on malformed CIDR input.
+ */
+int convert_ipv4_cidr_parms(char *p[], int network_idx, int max_idx,
+                            char *normalized[], struct gc_arena *gc);
+
 #endif /* ifndef OPTIONS_UTIL_H_ */
tests/unit_tests/openvpn/Makefile.am +20 -4
index 1128eb4..e277d40 100644
@@ -98,10 +98,11 @@
 ssl_testdriver_CFLAGS  = \
 	-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \
 	@TEST_CFLAGS@
-ssl_testdriver_LDFLAGS = @TEST_LDFLAGS@  $(OPTIONAL_CRYPTO_LIBS)
+ssl_testdriver_LDFLAGS = @TEST_LDFLAGS@  $(OPTIONAL_CRYPTO_LIBS) $(SOCKETS_LIBS)
 ssl_testdriver_SOURCES = test_ssl.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_management.c \
+	mock_signal.c \
 	mock_ssl_dependencies.c mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
@@ -121,6 +122,7 @@
 	$(top_srcdir)/src/openvpn/packet_id.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/run_command.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/ssl_openssl.c \
 	$(top_srcdir)/src/openvpn/ssl_mbedtls.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
@@ -221,13 +223,18 @@
 endif
 
 options_parse_testdriver_CFLAGS  = -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat @TEST_CFLAGS@
-options_parse_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn
+options_parse_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn \
+	$(SOCKETS_LIBS)
 options_parse_testdriver_SOURCES = test_options_parse.c \
 	mock_msg.c mock_msg.h test_common.h \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/options_parse.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/openvpn/platform.c
 
@@ -365,12 +372,16 @@
 	-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \
 	-DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
 
-misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
+misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ $(SOCKETS_LIBS)
 
 misc_testdriver_SOURCES = test_misc.c \
 	mock_msg.c test_common.h  \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
@@ -384,15 +395,20 @@
 
 push_update_msg_testdriver_LDFLAGS = \
 	@TEST_LDFLAGS@ \
-	-L$(top_srcdir)/src/openvpn
+	-L$(top_srcdir)/src/openvpn \
+	$(SOCKETS_LIBS)
 
 push_update_msg_testdriver_SOURCES = test_push_update_msg.c \
 	mock_msg.c \
 	mock_get_random.c \
+	mock_management.c \
+	mock_setenv.c \
+	mock_signal.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/options_util.c \
 	$(top_srcdir)/src/openvpn/otime.c \
+	$(top_srcdir)/src/openvpn/socket_util.c \
 	$(top_srcdir)/src/openvpn/list.c
 
 socket_testdriver_CFLAGS  = \
tests/unit_tests/openvpn/mock_setenv.c new file +39 -0
new file mode 100644
index 0000000..a35a295
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2026 OpenVPN Inc <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include "env_set.h"
+
+void
+setenv_str(struct env_set *es, const char *name, const char *value)
+{
+}
+
+void
+setenv_int(struct env_set *es, const char *name, int value)
+{
+}
tests/unit_tests/openvpn/mock_signal.c new file +47 -0

47 lines not on this page · raw message

tests/unit_tests/openvpn/test_options_parse.c +201 -14

239 lines not on this page · raw message

tests/unit_tests/openvpn/test_ssl.c +0 -2
index 2b73ee7..9182cb8 100644
@@ -51,8 +51,6 @@
 /* Mock function to be allowed to include win32.c which is required for
  * getting the temp directory */
 #ifdef _WIN32
-struct signal_info siginfo_static; /* GLOBAL */
-
 const char *
 strerror_win32(DWORD errnum, struct gc_arena *gc)
 {